home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / snip0493.zip / SCRNPICK.C < prev    next >
C/C++ Source or Header  |  1993-04-05  |  2KB  |  59 lines

  1. /* program:    mousword.c
  2.  * programmer: Ray L. McVay
  3.  * date:       20 Oct 1988
  4.  * modified:   15 Feb 93 by Bob Stout to use Bob Jarvis' MOUSE.H and MOUSE.C
  5.  *
  6.  * Demonstration of picking "words" off a text mode PC screen using a mouse.
  7.  * Submitted to the C_ECHO and placed in the public domain, 7 Jun 1992.
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include "mouse.h"
  13.  
  14. char word[80];
  15. int FAR *scrn = (int FAR *)0xb8000000L;   /* See VIO.H for a better way */
  16.  
  17. void getword(char *, int, int);
  18.  
  19. main(void)
  20. {
  21.       int done, b, x, y;
  22.  
  23.       ms_reset(&b); /* reset */
  24.       ms_show_cursor();
  25.       for (done = 0; !done; )
  26.       {
  27.             b = ms_get_mouse_pos(&x, &y);
  28.             if (b == 1)
  29.             {
  30.                   ms_hide_cursor();
  31.                   getword(word, x/8, y/8);
  32.                   do
  33.                   {
  34.                         b = ms_get_mouse_pos(&x, &y);
  35.                   } while (b);
  36.                   if (*word)
  37.                         printf("{%s}\n", word);
  38.                   ms_show_cursor();
  39.             }
  40.             else if (b > 1)
  41.                   done = 1;
  42.       }
  43.       ms_reset(&b);
  44.       return 0;
  45. }
  46.  
  47. void getword(char *w, int x, int y)
  48. {
  49.       int txs, txe, ci;
  50.     
  51.       for (txs = x; (txs >= 0) && ((scrn[80 * y + txs] & 255) != 32); txs--)
  52.             scrn[80 * y + txs] = (scrn[80 * y + txs] & 255) | 0x7000;
  53.       for (txe = x; (txe < 80) && ((scrn[80 * y + txe] & 255) != 32); txe++)
  54.             scrn[80 * y + txe] = (scrn[80 * y + txe] & 255) | 0x7000;
  55.       for (ci = txs + 1; ci < txe; ci++)
  56.             *w++ = (char)scrn[80 * y + ci];
  57.       *w = 0;
  58. }
  59.